package com.scs.application.modules.order.excel.handler;/**
 * @Description: 发货单导入
 */

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.utils.Reflections;
import com.scs.application.core.utils.SpringHolder;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.base.entity.Hospital;
import com.scs.application.modules.base.service.HospitalService;
import com.scs.application.modules.order.dto.DeliveryDTO;

/**
 * @ClassName HospitalDataHandler
 * @Description TODO
 */
public class HospitalDataHandler extends ExcelDataHandlerDefaultImpl<DeliveryDTO> {
    public String[] getNeedHandlerFields() {
        return new String[]{"医院代码"};
    }

    public Object importHandler(DeliveryDTO obj, String name, Object value) {
        if (!"医院代码".equalsIgnoreCase(name)) {
            return null;
        }
        if (value == null || StringUtils.isBlank(value.toString())) {
            return null;
        }
        String hospitalCode = value.toString();
        HospitalService hospitalService = SpringHolder.getBean(HospitalService.class);
        Hospital hospital = hospitalService.getOne(Wrappers.<Hospital>query().eq("code", hospitalCode));

        if (hospital != null && Reflections.getAccessibleField(obj, "hospitalId") != null) {
            Reflections.setFieldValue(obj, "hospitalId", hospital.getId());
        }
        return null;
    }

}
